import 'package:gold/base/view_model.dart';
import 'package:gold/http/apis.dart';
import 'package:gold/http/http.dart';

/// @description: 规则说明状态控制
/// @author tangzhentao
/// @created at 16:22 2025/3/8


class RulesViewmodel extends Viewmodel {
  /// 加载配置的key [Apis.config]
  final String config;
  /// html内容
  String content = '';

  RulesViewmodel(this.config);

  /// 加载配置
  Future loadConfig() async {
    setFailed();
    final result = await Http().request<String>(Apis.config, data: {'key': config}, showErrorMsg: false);
    if (result.success) {
      content = result.data?? '';
      if (content.isNotEmpty) {
        setSuccess();
      } else {
        setEmpty(msg: '暂无店铺规则，请稍后重试');
      }
    } else {
      setFailed(msg: result.msg);
    }
  }

  @override
  onRetry() => loadConfig();

  @override
  onReload() => loadConfig();
}